@extends('layouts.app')
@section('content')
    <div class="container">
        <div class="row">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h4>所有注册用户</h4>
                </div>
                <div class="panel-body">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>用户名</th>
                            <th>邮箱</th>
                            <th>状态</th>
                            <th>激活</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($users as $user)
                            <tr>
                                <td>{{$user->name}}</td>
                                <td>{{$user->email}}</td>
                                <td>
                                    @if($user->isOnline())
                                        <li class="text-success">在线</li>
                                    @else
                                        <li class="text-muted">离线</li>
                                    @endif
                                </td>
                                <td>
                                    @if($user->active)
                                        <li class="text-danger">已经激活</li>
                                    @else
                                        <li class="text-muted">未激活</li>
                                    @endif
                                </td>
                                <td>
                                    @if(Auth::user()->is_super)
                                        @if(!$user->active)
                                            <button class="btn btn-primary" onclick="active({{$user->id}})">激活</button>
                                        @else
                                            <button class="btn btn-warning" onclick="deactive({{$user->id}})">取消激活</button>
                                        @endif
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('more_scripts')
     <script>
          function active(user_id) {
              axios.put('api/v1/user/updateActive/'+user_id,{active:1}).then(
                result=>{

                    window.location.reload();
                }
              ).catch(
                  err=>{
                      if(err.response){
                          console.log(err.response);
                      }
                  }
              );
          }
          function deactive(user_id) {
              axios.put('api/v1/user/updateActive/'+user_id,{active:0}).then(
                  result=>{
                      window.location.reload();
                  }
              ).catch(
                  err=>{
                      if(err.response){
                          console.log(err.response);
                      }
                  }
              );
          }
     </script>
@stop
